package edu.gatech.cs2340.mule.model;
import java.io.Serializable;
import java.util.Random;


/**
 * 
 * This class allows the player to gamble money while he/she
 * is at the Pub in the town.
 * 
 * @author Keegan Nesbitt
 *
 */
public class Pub implements Serializable {
	private static final long serialVersionUID = 6210752345658510665L;
	
	private static final int[] ROUND_BONUS = {0, 50, 50, 50, 100, 100, 100, 100, 150, 150, 150, 150, 200};
	private static final int MAX_MONEY_BONUS = 250;
	private static final int[] TIME_BONUS = {50, 100, 150, 200};
	private static final int TIME_BONUS_TIER_ONE_MAX_TIME = 12;
	private static final int TIME_BONUS_TIER_TWO_MAX_TIME = 25;
	private static final int TIME_BONUS_TIER_THREE_MAX_TIME = 37;
	private static final int TIME_BONUS_TIER_FOUR_MAX_TIME = 50;
	
	/**
	 * 
	 * Calculates the amount of money the player won with his/her remaining time
	 * based upon the amount of time remaining and the current round
	 * 
	 * @param randomNumGenerator The Random object to be used to calculate the money bonus
	 * @param currentRound The current round of the game
	 * @param timeLeft The amount of time the player has left in his/her turn
	 * @return The amount of money the player won
	 */
	public int calculateMoneyBonus(Random randomNumGenerator, int currentRound, int timeLeft) {
		int timeBonus = calculateTimeBonus(timeLeft);
		int roundBonus = calculateRoundBonus(currentRound);
		
		int bonus =  roundBonus + randomNumGenerator.nextInt(timeBonus);
		
		if(bonus >= MAX_MONEY_BONUS) {
			return MAX_MONEY_BONUS;
		}
		else {
			return bonus;
		}
	} // end calculateMoneyBonus method
	
	/**
	 * 
	 * Calculates the time bonus using the time remaining
	 * 
	 * @param timeLeft The amount of time the player has left in his/her turn
	 * @return The time bonus used to calculate the overall bonus
	 */
	private int calculateTimeBonus(int timeLeft) {
		int timeBonus;
		
		if(timeLeft >= TIME_BONUS_TIER_THREE_MAX_TIME && timeLeft <= TIME_BONUS_TIER_FOUR_MAX_TIME)	{
			timeBonus = TIME_BONUS[0];
		}
		else if(timeLeft >= TIME_BONUS_TIER_TWO_MAX_TIME && timeLeft < TIME_BONUS_TIER_THREE_MAX_TIME) {
			timeBonus = TIME_BONUS[1];
		}
		else if(timeLeft >= TIME_BONUS_TIER_ONE_MAX_TIME && timeLeft < TIME_BONUS_TIER_TWO_MAX_TIME) {
			timeBonus = TIME_BONUS[2];
		}
		else {
			timeBonus = TIME_BONUS[3];
		}
		
		return timeBonus;
	} // end calculateTimeBonus method
	
	/**
	 * 
	 * Calculates the round bonus using the current round of the game
	 * 
	 * @param currentRound The current round of the game
	 * @return The round bonus used to calculate the overall bonus
	 */
	private int calculateRoundBonus(int currentRound) {
		return ROUND_BONUS[currentRound];
	} // end calculateRoundBonus method
} // end Pub class
